<?php
session_start();
include("../config/connect.php");
include("../public/common.php");

if(HasLogin())
{
	header("Location:../user");	// 跳转到个人中心
	exit;
}

$ref = CheckUrlParamNoDie("ref");
$email = trim(GetPostParamStr("emailaddress"));
$nickname = trim(GetPostParamStr("nickname"));
$psw = md5(trim(GetPostParamStr("password")));
$sex = trim(GetPostParamStr("gender"));

if( isset( $_POST["newRegister_submit"] ))
{
	$sql = "select id from tsj_user where email='$email' limit 1";
	$result = mysql_query( $sql );
	if (mysql_num_rows($result) > 0)
	{
		// 已经注册过了，提示他去登录
		$url = "Location:../user";
		header($url);
		exit;
	}
	else
	{
		$sql = "insert into tsj_user (email,nick_name,password,sex) values ('$email', '$nickname','$psw', $sex)";
		mysql_query( $sql );
		if (mysql_affected_rows() == 0)
		{
			// 插入失败，提示
		}
		else
		{
			// 登录信息
			$_SESSION["isoauth"] = 0;
			$_SESSION["email"] = $email;
			$_SESSION["userid"] = mysql_insert_id();
			$_SESSION["nickname"] = $nickname;
			$_SESSION["right"] = 0;
				
			// 跳转
			$url = "Location:../user/edit.php";	// 跳到用户个人信息处
			header($url);
		}
	}
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>注册</title>
<link type="text/css" rel="stylesheet" href="../css/base.css" />
<link type="text/css" rel="stylesheet" href="../css/newreg.css" />
<script type="text/javascript" src="../js/jquery-1.4.4.js"></script>
<script type="text/javascript" src="../js/base.js"></script>
</head>

<body>
<script type="text/javascript">
	$("#cuu_password_hint").html("<p style='float:left; line-height:200%'><img src='../images/register/confirm_suc.gif'/></p>");
</script>
<div id="wrapper">
<!---head kaishi--->
     <?php
		 include("../headtop.php"); 
	?>
<!-----head 结束----->
<div id="frame_page_wrapper">
	<div id="frame_page_wrapper_content">
			<!-- google_ad_section_start -->
		<div class="register-page-wrapper" id="loginForm">
			<div class="left newRegFromMain user-left">
				<div id="regWarning">
                    <div class="bottom-left-w" style="width: 158px;">
                    	<div class="bottom-right-w">
                        	<div class="top-left-w">
                            	<p class="top-right-w messageBox"></p>
                            </div>
                        </div>
                    </div>
                </div>
			<div id="regNotice">
			<div class="bottom-left-t" style="width: 158px;">
				<div class="bottom-right-t">
					<div class="top-left-t">
						<p class="top-right-t messageBox"></p>
					</div>
				</div>
			</div>
		</div>
		<div>
			<h1>注册 兔丝街 居民证</h1>
			<div class="reg-desc">精品连连，让您爱不惜手！享受兔丝特权，购物更省钱！</div>
		</div>
		<div class="dash-line"></div>
		<form id="form" method="post" onsubmit="return registerAction.checkRegisterForm();" action="?">

				<div class="oneline">
			<div class="titleBox left">电子邮箱：<span class="required">*</span></div>
			<div class="inputBox left">
            	<input type="text" onfocus="return registerAction.focusEmailInput();" onblur="return registerAction.blurEmailInput(this);" value="" id="emailaddress" name="emailaddress" class="input1">
            					</div>
			<div class="hints left"></div>
			<div style="clear:both"></div>
		</div>

				<div class="oneline">
			<div class="titleBox left">取个昵称：<span class="required">*</span></div>
			<div class="inputBox left">
				<input type="text" onfocus="return registerAction.focusNicknameInput();" onblur="return registerAction.blurNicknameInput();" value="" id="nickname" name="nickname" class="input1">
			</div>
			<div class="hints left"></div>
			<div style="clear:both"></div>
		</div>
        

				<div class="oneline">
			<div class="titleBox left">设置密码：<span class="required">*</span></div>
			<div class="inputBox left">
				<input type="password" onfocus="$('#rePwdRow').show(); return registerAction.focusPasswordInput();" onblur="return registerAction.blurPasswordInput();" value="" id="password" name="password" class="input1">
			</div>
			<div class="hints left"></div>
			<div style="clear:both"></div>
		</div>
			<div class="oneline" style="display:none;" id="rePwdRow">
			<div class="titleBox left">确认密码：<span class="required">*</span></div>
			<div class="inputBox left">
				<input type="password" onfocus="return registerAction.focusVPasswordInput();" onblur="return registerAction.blurVPasswordInput();" value="" id="confirm_password" name="confirm_password" class="input1">
			</div>
			<div class="hints left"></div>
			<div style="clear:both"></div>
		</div>


				<div class="oneline">
			<div class="titleBox left">性别：<span class="required">*</span></div>
			<div id="gender-wrapper" class="inputBox left">
				<input type="radio" class="info_radio01" value="0" id="genderF"  onblur="return registerAction.blurGenderRadio();" name="gender">&nbsp;女
				&nbsp;&nbsp;&nbsp;&nbsp;
				<input type="radio" class="info_radio01" value="1" id="genderM"  onblur="return registerAction.blurGenderRadio();" name="gender">&nbsp;男
			</div>
			<div class="hints left"></div>
			<div style="clear:both"></div>
		</div>

        <div class="oneline">
			<div class="titleBox left">&nbsp;</div>
			<div style="border:0px;" class="inputBox left">
				<input type="checkbox" checked="checked" id="agreement" onclick="if(this.checked) document.getElementById('newRegister_submit').disabled='';else document.getElementById('newRegister_submit').disabled='true'">
                	我同意<a target="_blank" href="agree.php" class="red">兔丝街注册条款</a>
             </div>
             <div style="clear:both"></div>
		</div>
		
		<div class="oneline">
			<div class="titleBox left">&nbsp;</div>
			<div class="inputBox left">
            	<input type="hidden" name="action" value="submitted">
				<input type="submit" class="button-100 button" id="newRegister_submit" name="newRegister_submit" value="立即注册" >
             </div>
             <div style="clear:both"></div>
		</div>
		</form>

	</div>

            <div class="left newRegFromRight">
                <div class="reg-desc">已有兔丝街账号？<a href="login.php">直接登录</a></div>
                <div>
                    你也可以用站外账号登录:<br><br>
                    <a href="../public/weibosdk/oauth"><img src="http://www.tusijie.com/images/linksina.png"></a><br><br>
                    <a href="../public/qqsdk/oauth/redirect_to_login.php"><img src="http://www.tusijie.com/images/connect_Q.png"></a><br><br>
                </div>
            </div>
            <div style="clear:both"></div>
        </div>
        <!-- google_ad_section_end -->
        <div class="clear-fix"></div>
        <!-- google_ad_section_start(weight=ignore) -->	
	</div>
	<div style="clear:both"></div>
<!-- google_ad_section_end -->
</div>
</div>
<!---网尾 kaishi--->
 <?php
     include("../networkend.php"); 
?>
<!------------>
</div>
</body>
</html>

<script type="text/javascript">
var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://");
document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3F22b7662ec7d02c816ddfd8f6df6e5cea' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-20984072-3']);
  _gaq.push(['_trackPageview']);
  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
</script>